<template>
    <div class = "Addbaseslideshow" >
    <el-container v-loading = "loading">
        <el-container>
        <el-main>
            <div class = "Box-wrapper" >
                <el-breadcrumb separator="/">
                <el-breadcrumb-item style="font-weight: bold;cursor:pointer" :to="{ path: 'Addbase' }">基地管理</el-breadcrumb-item>
                <el-breadcrumb-item style="font-weight: bold;cursor:pointer" @click.native = "goBack">基地项目</el-breadcrumb-item>
                <el-breadcrumb-item>轮播图</el-breadcrumb-item>
                </el-breadcrumb>
                <el-button style="float:right" @click = "newly">新增</el-button>
                <el-table
                :data="tableData"
                style="width: 100%">
                <el-table-column
                    prop="id"
                    align="center"
                    label="ID">
                </el-table-column>
                <el-table-column
                    prop="title"
                    align="center"
                    label="标题">
                </el-table-column>
                <el-table-column
                    prop="weight"
                    label="权重"
                    align="center"
                    >
                </el-table-column>
                 <el-table-column
                    prop="createdAt"
                    label="创建时间"
                    align="center"
                    >
                </el-table-column>
            <el-table-column label="操作" align="center">
                <template slot-scope="scope">
                    <el-button
                    size="mini"
                    @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                    <el-button
                    size="mini"
                    type="danger"
                    @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                </template>
                </el-table-column>
                </el-table>
            </div>
        </el-main>
        </el-container>
        </el-container>
    </div>
</template>
<script>
import Vue from "vue";
import transitionTime from '../../transitionTime.js'
export default {
    data(){
        return{
            tableData:[],
            loading:false,
        }
    },
    created() {
        this.List()
    },
    methods: {
        List(){
            this.loading = true
            this.baseId = this.$route.query.baseId
            if(this.baseId) {
                this.$api.Basetoaddordelete.slideshow(this.baseId).then(res => {
                   this.tableData = res.data
                   for(let i = 0; i < this.tableData.length; i++){
                       this.tableData[i].createdAt = transitionTime(this.tableData[i].createdAt)
                   }
                   this.loading = false
                })
            }
        },
        //新增
        newly(){
            this.$router.push(`Addbaseslideshowredact?baseId=${this.baseId}`)
        },
        
        //编辑
        handleEdit(index,item){
            this.$router.push({path:`Addbaseslideshowredact?baseId=${this.baseId}&id=${item.id}`,query:{item:item}})
        },
        //删除
        handleDelete(index,item){
            this.$confirm('是否删除?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
                }).then(() => {
                this.$api.Basetoaddordelete.BaseslideshowDelete(item.id).then(res => {
                if(res.code === 200){
                  this.tableData = this.tableData.filter(data => data.id !== item.id)
                  this.$message({
                    type: 'success',
                    message: '删除成功!'
                });  
                } else {
                    this.open1('失败','删除失败','warning')
                }
                }).catch(err => {
                console.log(err)
                })
                }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });          
                });
        },
        //返回按钮
        goBack(){
        //   let form = {
        //       id:this.form.itemtwo,
        //       BaseId:this.form.BaseIdone
        //   }
          this.$router.push(`/Addbasethree?baseId=${this.baseId}`)
        },
    },
}
</script>
<style scoped>

</style>
